#pragma once

#include <iostream>
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <functional>

using namespace std;

class ThreadPool {
public:
    explicit ThreadPool(size_t thread_count = 4);
    ~ThreadPool();

    void enqueue(function<void()> task);
private:
    void worker_loop();

    vector<thread> workers;
    mutex mtx;
    condition_variable cv;
    atomic<bool> stop;
    queue<function<void()>> tasks;
};
